package com.pm;

import java.io.File;
import java.util.List;

import org.apache.commons.digester3.Digester;
import org.apache.commons.digester3.binder.DigesterLoader;

import com.util.MyRules;

public class Pm_Main {
	private static List<Pm_file> pmfileList;
	
	public static void parsePmConfig(){
		String pmConfigfile = System.getProperty("user.dir")+"\\config\\nrm_pm.xml";
		String pmRulefile = System.getProperty("user.dir")+"\\config\\pm_rule.xml";
        File input = new File(pmConfigfile);  
        DigesterLoader digesterLoader = DigesterLoader.newLoader(new MyRules(pmRulefile));
        Digester digester = digesterLoader.newDigester();
        Nrm_pm_xml root;
        try {
			root = (Nrm_pm_xml)digester.parse(input);
			pmfileList = root.getPmfiles();
		} catch (Exception e) {
			System.exit(1);
		} 
	}
	
	public static List<Pm_file> getPmfileList() {
		return pmfileList;
	}
	
	public static void main(String[] args){
		Pm_Main.parsePmConfig();
		List<Pm_file> list1 = Pm_Main.getPmfileList();
		
		for(int i=0;i<list1.size();i++){
			System.out.println(list1.get(i).getXmlnename());
			List<Pmfileheader> fileheaders = list1.get(i).getPmheaders().get(0).getPmfileheaders();
			for(int j=0;j<fileheaders.size();j++){
				System.out.println(fileheaders.get(j).getHeadername() + " "+fileheaders.get(j).getValue());
			}
			List<Measurements> mts = list1.get(i).getMeasurements();
			for(int k=0;k<mts.size();k++){
				System.out.println(mts.get(k).getObjType() + " "+ mts.get(k).getSqlelement());
			}
		}
	}
}
